package com.xugou.service.Impl;

import com.xugou.dao.DeptDao;
import com.xugou.dao.OrderDao;
import com.xugou.pojo.Dept;
import com.xugou.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.util.List;

public class DeptServiceImpl implements DeptService {

    @Autowired
    @Qualifier("deptDao")
    private DeptDao deptDao;

    public void setDeptDao(DeptDao deptDao) {
        this.deptDao = deptDao;
    }

    //获取所有部门员工信息
    public List<Dept> getAllDeptEmpList() {

        List<Dept> empList = deptDao.getEmp();
        if (empList!=null){
            return empList;
        }
        return null;
    }
    
    //增加新部门
    public boolean addNewDept(String deptName){

        Integer num = deptDao.getDeptNum();
        num ++;
        boolean flag = deptDao.addDept(new Dept(num,deptName));
       if (flag){
           return true;
       }else {
            return false;
       }
    }

    public List<Dept> getAllDeptList() {
        List<Dept> deptList = deptDao.getDeptList();
        if(deptList!=null){
            return deptList;
        }else {
            return null;
        }
    }

    public boolean delDept(int id) {
        boolean b = deptDao.delDept(id);
        if (!b){
             return false;
        }
        return true;
    }

    public int updateDept(Dept dept) {
        int i = deptDao.updateDept(dept);
        return i;
    }
//    由id获取部门


    public Dept getDeptById(int id) {
        Dept deptById = deptDao.getDeptById(id);
        return deptById;

    }

}
